<?php

/**
 * ContactForm class.
 * ContactForm is the data structure for keeping
 * contact form data. It is used by the 'contact' action of 'SiteController'.
 */
class UserAddForm extends CFormModel
{
	public $firstname;
	public $lastname;
	public $email;
	public $username;
	public $password;
	public $password_confirm;
	public $status;
	public $id_user_role;

	/**
	 * Declares the validation rules.
	 */
	public function rules()
	{
		return array(
			array('firstname, lastname, email, username, password, status, password_confirm', 'required'),
			array('firstname, lastname, email, username, password, status', 'length', 'max' => 50),
			array('email', 'email'),
			array('password, username', 'length', 'min' => 5),
			array('password', 'compare', 'compareAttribute'=>'password_confirm'),
		);
	}

	/**
	 * Declares customized attribute labels.
	 * If not declared here, an attribute would have a label that is
	 * the same as its name with the first letter in upper case.
	 */
	public function attributeLabels()
	{
		return array(
			'firstname' => t('info', 'First Name'),
			'lastname' => t('info', 'Last Name'),
			'email' => t('info', 'Email'),
			'username' => t('info', 'Username'),
			'password' => t('info', 'Password'),
			'password_confirm' => t('info', 'Confirm Password'),
			'status' => t('info', 'Status'),
			'id_user_role' => t('info', 'Role'),
		);
	}
	
	public function getFieldLabel($field)
	{
		$labels = $this->attributeLabels();
		
		return empty($labels[$field])? '' : $labels[$field];
	}
	
	public function statusDatasource()
	{
		return array(
			User::STATUS_ACTIVE => 'Status: Active',
			User::STATUS_SUSPENDED => 'Status: Suspended'
		);
	}
	
	public function listExistedRoles()
	{
		return CHtml::listData(UserRole::model()->findAll(), 'id_user_role', 'namedropdownlabel');
	}
	
}